import { defineStore } from "pinia";
import { getUserInfo, getMenuInfo } from "@/api/user";
export const userStore = defineStore("baseCommon", {
  // 为了完整类型推理，推荐使用箭头函数
  state: () => {
    return {
      userInfo: null,
      menuData: [],
      load: false
    };
  },
  getters: {
    isLoggedIn: (state) => state.userInfo,
    menuList: (state) => state.menuData
  },

  actions: {
    async registerUser() {
      try {
        const userInfo = await getUserInfo();
        this.userInfo = userInfo.data;
      } catch (error) {
        return error;
      }
    },

    async registryMenu() {
      try {
        const menuData = await getMenuInfo();
        this.menuData = menuData.data;
      } catch (error) {
        throw error
      }
    }
  },
});
